#ifndef _OI_PLSCANNERCORE_USERMANAGE_H_
#define _OI_PLSCANNERCORE_USERMANAGE_H_

#include "PLScannerCore/OiPLScannerCore.hpp"

namespace Oi
{
    namespace PLScannerCore
    {
        enum  PermissionType
        {
            PT_AddDelFormular = 0x00000001,
            PT_ModifyFormular = 0x00000002,
            PT_ViewData = 0x00000004,
            PT_ViewStatistics = 0x00000008,
            PT_ViewFPYStatistics = 0x00000010,
            PT_ViewTimeStatistics = 0x00000020,
            PT_Exit = 0x00000040,
            PT_SettingBasic = 0x00000080,
            PT_SettingPermission1 = 0x00000100,
            PT_UserManger = 0x00000200,
            PT_Calib = 0x00000800,
            PT_DeleteData = 0x00001000,
            PT_Verification = 0x00002000,
            PT_ViewXRGraphics = 0x00004000,
            PT_ZeroCalib = 0x00008000,

            PT_Technologist = PT_AddDelFormular | PT_ModifyFormular | PT_Calib | PT_Verification,
            PT_Administrator = 0xFFFFFFFF,
        };

        class UserParams
        {
        public:

            UserParams() : permission(0), team(0)
            {

            }

            UserParams(const UserParams& p)
            {
                *this = p;
            }

            UserParams& operator=(const UserParams& p)
            {
                id = p.id;
                team = p.team;
                name = p.name;
                permission = p.permission;
                password = p.password;
                return *this;
            }

        public:
            QString id;
            int team;
            QString name;
            int permission;
            QString password;
        };

        class OI_PLSCANNER_CORE_API UserManage
        {

        public:
            UserManage();

        public:
            bool isValid();

            void loadParams();

            void saveParams();

        public:
            QString current() const;
            int setCurrent(const QString id, QString password);

            QString name(QString id = QString()) const;
            int team(QString id = QString()) const;
            int permission(QString id = QString()) const;
            QString password(QString id = QString()) const;

        public:
            QStringList users() const;
            UserParams& params(QString id = QString());
            QMap<QString, UserParams>& paramsMap();

        public:
            static UserManage* instance();

        private:
            OI_DISABLE_COPY(UserManage);
            OI_DECLARE_IMPL(UserManage);
        };
    }
}


#endif
